<template>
	<view class="my-coupon">
		<view class="tabs">
			<u-tabs name="cate_name" count="cate_count" :list="list" :is-scroll="false" :current="current"
				@change="change" active-color="#FA436A"></u-tabs>
				<u-card v-for="item in Data" :title="item.storeName">
					<view slot="head">
						<template v-for="b in item.orderDetails">
							<template v-for="c in b.stores">
								<u-avatar :src="c.storeImg"></u-avatar>{{c.storeName}}
							</template>							
						</template>
					</view>
					<view slot="body">
						<template v-for="ite in item.orderDetails">
							<template v-for="a in ite.pictures">
								<image style="width: 200px; height: 200px;" :src="a.pictureUrl" mode="aspectFill"></image>
							</template><br>
							<u-icon style="margin-top: 10px;" size="34" color="" :label="ite.orderDetailName"></u-icon>		
						</template>											
					</view>
					<view class="count" slot="foot">
						<u-button type="primary" size="default" plain :ripple="true" @click="open(item)" ripple-bg-color="#FA436A">退款</u-button>
					</view>
				</u-card>
				<u-modal v-model="show"  @confirm="towReturnAdd">
					<view class="slot-content">
						<u-form ref="uForm">
							<u-form-item label="退货原因" label-width="70px"><u-input v-model="returnGoodsReason" /></u-form-item>			
						</u-form>
					</view>
				</u-modal>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				show:false,
				Data:[],
				list: [{
					cate_name: '退货交易中',
					type:0
				}, 
				{
					cate_name: '已退货',
					type:1
				},
				 ],
				current: 0,
				beforeUserId:'',
				returnGoodsReason:'',
				tui:''
			}
		},
		onLoad() {
			uni.getStorage({
				key:"beforeUser",
				success: (res) => {
					this.beforeUserId = res.data.beforeUserId
				}
			})
			this.change(0);
		},
		methods: {
			open(data) {
					this.show = true;
					this.tui = data
					
				},
			change(index) {
				this.current = this.list[index].type;
				if(this.current == 0){
					console.log(1111)
					uni.request({
						url: 'http://localhost:9090/order/bgs/order/TowGetOrder',
						method: 'GET',
						data:{
							beforeUserId: this.beforeUserId
						},
						success: (res) => {
							this.Data = res.data.data.list
							console.log(this.Data)
							
						}
					});
				}else if(this.current == 1){
					console.log(222)
					uni.request({
						url: 'http://localhost:9090/order/bgs/order/TowTuiOrder',
						method: 'GET',
						data:{
							beforeUserId: this.beforeUserId
						},
						success: (res) => {
							this.Data = res.data.data.list
							console.log(this.Data)
						}
					});
				}
			},
			towReturnAdd(){
				uni.request({
					url: 'http://localhost:9090/return/bgs/return-goods/TowReturnAdd',
					method: 'POST',
					data:{
						data: this.tui,
						returnGoodsReason:this.returnGoodsReason
					},
					success: (res) => {
						this.Data = res.data.data.list
						console.log(res)
						uni.request({
							url: 'http://localhost:9090/order/bgs/order/TowOrderUp',
							method: 'GET',
							data:{
								beforeUserId: this.beforeUserId
							},
							success: (res) => {
								console.log("修改成功")
							}
						});
					}
				});
			}
		}
	};
</script>
<style lang="scss">
	.tabs {
		width: 100%;
	}
	.count {
		float: right;
		margin-bottom: 12px
	}
	.slot-content {
			font-size: 28rpx;
			color: $u-content-color;
			padding-left: 30rpx;
	}
</style>
